<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>任务首页</title>
    <meta name="author" content="易古2012"/>
    <meta name="site" content="https://blog.52itstyle.com"/>
    <link rel="stylesheet" th:href="@{/iview/iview.css}">
    <script th:src="@{/libs/jquery-3.2.1.min.js}" type="text/javascript"></script>
    <script th:src="@{/libs/vue.min.js}" type="text/javascript"></script>
    <script th:src="@{/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/iview/iview.min.js}" type="text/javascript"></script>
    <style type="text/css">
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak style="margin: 30px">
    <template>
        <i-form v-ref:form-user :model="formuser" :rules="ruleValidate" :label-width="80">
            <Form-item label="用户ID" prop="userId">
                <i-input disabled v-model="formuser.userId" :value.sync="formuser.userId"
                         placeholder="请输入用户ID"></i-input>
            </Form-item>
            <Form-item label="用户名" prop="username">
                <i-input v-model="formuser.username" :value.sync="formuser.username" placeholder="请输入用户名"></i-input>
            </Form-item>
            <Form-item label="密码" prop="password">
                <i-input v-model="formuser.password" :value.sync="formuser.password" placeholder="请输入密码"></i-input>
            </Form-item>
        </i-form>
    </template>
</div>
<script type="text/javascript">
    var vm = new Vue({
        el: '#app',
        data: {
            formuser: {
                userId: '',
                username: '',
                password: '',
                //旧用户ID  用于修改
                olduserId: '',
                oldusername: ''
            },
            ruleValidate: {
                username: [
                    {required: true, message: '用户名不能为空', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '密码不能为空', trigger: 'blur'}
                ]
            }
        },
        methods: {
            //新建任务(略简单)
            acceptClick: function () {
                //Validate不起作用MD
                var user = vm.formuser;
                if (vm.formuser.username == "" || vm.formuser.password == "") {
                    alert("请输入以上完整信息");
                    return;
                }

                if (vm.formuser.userId == "") {
                    $.ajax({
                        url: "../user/add",
                        type: "post",
                        data: user,
                        success: function (result) {
                            if (result.code == "0") {
                                window.parent.location.reload();
                            } else {
                                vm.$Notice.error({
                                    desc: '系统异常'
                                });
                            }
                        }
                    });
                } else {
                    $.ajax({
                        url: "../user/update",
                        type: "post",
                        data: user,
                        success: function (result) {
                            if (result.code == "0") {
                                window.parent.location.reload();
                            } else {
                                vm.$Notice.error({
                                    desc: '系统异常'
                                });
                            }
                        }
                    });
                }

            }
        },
        created: function () {

        }
    })

</script>
</body>
</html>
